#include <algorithm>
#include <vector>
#include <iostream>

int main() {
    // 定义一个Lambda表达式，根据参数ascending决定是升序还是降序排序
    auto custom_sort = [](bool ascending) {
        return [ascending](int a, int b) {
            return ascending ? a < b : a > b;
        };
    };

    std::vector<int> numbers = {3, 1, 4, 1, 5, 9, 2, 6, 5};

    // 使用custom_sort(true)进行升序排序
    std::sort(numbers.begin(), numbers.end(), custom_sort(true));
    std::cout << "Ascending order: ";
    for (int num : numbers) {
        std::cout << num << " ";
    }
    std::cout << std::endl;

    // 使用custom_sort(false)进行降序排序
    std::sort(numbers.begin(), numbers.end(), custom_sort(false));
    std::cout << "Descending order: ";
    for (int num : numbers) {
        std::cout << num << " ";
    }
    std::cout << std::endl;

    return 0;
}